package com.situ.staff.score.service.Impl;

import java.sql.SQLException;
import java.util.List;

import com.situ.staff.score.dao.ScoreDao;
import com.situ.staff.score.model.ScoreModel;
import com.situ.staff.score.service.IScoreService;

public class ScoreServiceImpl implements IScoreService {
	ScoreDao dao = new ScoreDao();

	@Override
	public String insert(ScoreModel model) throws SQLException {
		ScoreModel m0 = dao.selectModel(model);
		if(m0==null) {
			return dao.insert(model)+"";
		}else {
			
			return "repeat";
		}
	}

	@Override
	public String delete(ScoreModel model) throws SQLException {
		
		return dao.delete(model)+"";
	}

	@Override
	public String update(ScoreModel model) throws SQLException {
			return dao.updateActive(model)+"";
	}

	@Override
	public List<ScoreModel> selectList(ScoreModel model) throws SQLException {
		String codeEmp = model.getCodeEmp();
		model.setCodeEmp(codeEmp == null ? "%%" : "%" + codeEmp + "%");
		String codePro = model.getCodePro();
		model.setCodePro(codePro == null ? "%%" : "%" + codePro + "%");
//		System.out.println(model.toString());
//		System.out.println(dao.selectList(model).toString());
		return dao.selectList(model);
	}

	@Override
	public ScoreModel selectModel(ScoreModel model) throws SQLException {
//		System.out.println(model.toString());
		return dao.selectModel(model);
	}

	@Override
	public Integer selectCount(ScoreModel model) throws SQLException {
		ScoreModel m0 = new ScoreModel();
		String codeEmp = model.getCodeEmp();
		m0.setCodeEmp(codeEmp == null ? "%%" : "%" + codeEmp + "%");
		String codePro = model.getCodePro();
		m0.setCodePro(codePro == null ? "%%" : "%" + codePro + "%");
		return dao.selectCount(m0);
	}
}
